package org.example;

import java.time.LocalDate;

public class YesterDate {
    public static String getYesterDate(int year, int month, int day) {
        // 检查输入是否符合规则
        if (year < 1900 || year > 2050) {
            throw new IllegalArgumentException("Year must be between 1900 and 2050");
        }
        if (month < 1 || month > 12) {
            throw new IllegalArgumentException("Month must be between 1 and 12");
        }
        if (day < 1 || day > 31) {
            throw new IllegalArgumentException("Day must be between 1 and 31");
        }

        try {
            // 使用 LocalDate 计算前一天日期
            LocalDate date = LocalDate.of(year, month, day);
            LocalDate yesterDate = date.minusDays(1);
            return yesterDate.toString(); // 以 "YYYY-MM-DD" 格式返回
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid date input");
        }
    }
}
